package com.zzjson.thread;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.thread</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年09月16日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class CyclicBarrierTest {
	static CyclicBarrier cyclicBarrier = new CyclicBarrier(11);

	public static void main(String[] args) throws BrokenBarrierException, InterruptedException {
		ExecutorService executorService = Executors.newFixedThreadPool(10);
		for (int i = 0; i < 10; i++) {
			executorService.submit(() -> {
				System.out.println("oo");
				try {
					cyclicBarrier.await();
					System.out.println("end");
				} catch (InterruptedException e) {
					e.printStackTrace();
				} catch (BrokenBarrierException e) {
					e.printStackTrace();
				}
			});
		}
		cyclicBarrier.await();
		System.out.println("main-end");
		executorService.shutdown();
	}

}